package cn.hairui.blog.mapper;

import cn.hairui.blog.model.Book;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;
import java.util.Map;

/**
 * @author lihairui
 * @version V1.0
 * @date: 2019/7/28 22:17
 */
@Mapper
public interface BookMapper extends BaseMapper<Book> {

    @Select("SELECT * FROM BOOK LIMIT #{start},#{end}")
    List<Book> findLimited(int start, int end);

    @Select("SELECT id,BOOK_NAME AS bookName,author,PUBLISH_DATE AS publishDate,url,LOCAL_PATH AS localPath,ADD_DATE AS addDate FROM BOOK")
    List<Map> listMgr();

    @Select("SELECT * FROM BOOK WHERE BOOK_NAME=#{bookName}")
    List<Book> findByBookName(String bookName);

    @Delete("DELETE FROM BOOK WHERE ID=#{id}")
    void deleteById(int id);

    @Select("SELECT * FROM BOOK WHERE ID=#{id}")
    Book find(int id);

    @Select("SELECT * FROM BOOK ORDER BY ID DESC")
    List<Book> list();

    @Update("UPDATE BOOK SET COVER=#{fileName} WHERE ID=#{id}")
    void updateCover(Integer id, String fileName);
}
